﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class EmptyLocationRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15231;
        protected GridView gvLoc;
        protected HtmlInputHidden hdnFrom;
        protected Label lblMsg;
        protected Label lblReceiptInquiryList;
        protected Label lblTotalCubicCapacity;
        protected Label lblTotalCubicCapacityText;
        protected Label lblTotalWeightCapacity;
        protected Label lblTotalWeightCapacityText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal TotalCubicCapacity;
        private decimal TotalWeightCapacity;
        protected UpdatePanel up1;

        private void BindData2LocList(EmptyLocationRptQueryEntity emptyLocationRptQuery)
        {
            this.PagerFooter.CurrentPage = int.Parse(emptyLocationRptQuery.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetEmptyLocationRptInfo(emptyLocationRptQuery);
            base.BindData2GridView(this.gvLoc, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            emptyLocationRptQuery.IsGetAll = true;
            string currentPageIndex = emptyLocationRptQuery.CurrentPage;
            emptyLocationRptQuery.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetEmptyLocationRptInfo(emptyLocationRptQuery))
                {
                    base.Export2Excel("EmptyLocationRpt.xls", "15231", this.gvLoc, ds);
                }
            }
            finally
            {
                emptyLocationRptQuery.IsGetAll = false;
                emptyLocationRptQuery.CurrentPage = currentPageIndex;
                this.SetEmptyLocationRptQueryEntity(emptyLocationRptQuery);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            emptyLocationRptQuery.CurrentPage = "0";
            this.BindData2LocList(emptyLocationRptQuery);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            emptyLocationRptQuery.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2LocList(emptyLocationRptQuery);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            emptyLocationRptQuery.LOC = "";
            emptyLocationRptQuery.ZONE_ID = "";
            emptyLocationRptQuery.LOC_USAGE = "";
            emptyLocationRptQuery.ABC = "";
            emptyLocationRptQuery.STATUS = "";
            emptyLocationRptQuery.LOC_FLAG = "";
            this.BindData2LocList(emptyLocationRptQuery);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            if (int.Parse(emptyLocationRptQuery.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                emptyLocationRptQuery.CurrentPage = (int.Parse(emptyLocationRptQuery.CurrentPage) + 1).ToString();
                this.BindData2LocList(emptyLocationRptQuery);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            if (int.Parse(emptyLocationRptQuery.CurrentPage) > 0)
            {
                emptyLocationRptQuery.CurrentPage = (int.Parse(emptyLocationRptQuery.CurrentPage) - 1).ToString();
                this.BindData2LocList(emptyLocationRptQuery);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
            this.BindData2LocList(emptyLocationRptQuery);
        }

        private EmptyLocationRptQueryEntity GetEmptyLocationRptQueryEntity()
        {
            return (base.PageQueryEntitySession as EmptyLocationRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
                emptyLocationRptQuery.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2LocList(emptyLocationRptQuery);
            }
        }

        protected void gvLoc_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15231", this.gvLoc);
        }

        protected void gvLoc_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (((Label) e.Row.FindControl("lblCubicCapacity")) != null)
                {
                    this.TotalCubicCapacity += decimal.Parse(((Label) e.Row.FindControl("lblCubicCapacity")).Text);
                }
                if (((Label) e.Row.FindControl("lblWeightCapacity")) != null)
                {
                    this.TotalWeightCapacity += decimal.Parse(((Label) e.Row.FindControl("lblWeightCapacity")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalCubicCapacityText.Text = base.GetPreferenceDigit(this.TotalCubicCapacity);
                this.lblTotalWeightCapacityText.Text = base.GetPreferenceDigit(this.TotalWeightCapacity);
            }
        }

        protected void gvLoc_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                EmptyLocationRptQueryEntity emptyLocationRptQuery = this.GetEmptyLocationRptQueryEntity();
                emptyLocationRptQuery.SortField = e.SortExpression;
                if (emptyLocationRptQuery.SortDirection == "ASC")
                {
                    emptyLocationRptQuery.SortDirection = "DESC";
                }
                else if (emptyLocationRptQuery.SortDirection == "DESC")
                {
                    emptyLocationRptQuery.SortDirection = "ASC";
                }
                this.BindData2LocList(emptyLocationRptQuery);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            EmptyLocationRptQueryEntity emptyLocationRptQuery = new EmptyLocationRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    emptyLocationRptQuery.LOC = this.PreviousPage.Loc;
                    emptyLocationRptQuery.ZONE_ID = this.PreviousPage.ZoneID;
                    emptyLocationRptQuery.LOC_USAGE = this.PreviousPage.LocUsage;
                    emptyLocationRptQuery.ABC = this.PreviousPage.Abc;
                    emptyLocationRptQuery.STATUS = this.PreviousPage.Status;
                    emptyLocationRptQuery.LOC_FLAG = this.PreviousPage.LocFlag;
                }
                else
                {
                    emptyLocationRptQuery.LOC = "";
                    emptyLocationRptQuery.ZONE_ID = "";
                    emptyLocationRptQuery.LOC_USAGE = "";
                    emptyLocationRptQuery.ABC = "";
                    emptyLocationRptQuery.STATUS = "";
                    emptyLocationRptQuery.LOC_FLAG = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            emptyLocationRptQuery.IsGetAll = false;
            emptyLocationRptQuery.CurrentPage = "0";
            emptyLocationRptQuery.PageSize = this.gvLoc.PageSize.ToString();
            emptyLocationRptQuery.SortField = "LOC";
            emptyLocationRptQuery.SortDirection = "DESC";
            this.PagerFooter.PageSize = this.gvLoc.PageSize;
            this.SetEmptyLocationRptQueryEntity(emptyLocationRptQuery);
            this.BindData2LocList(emptyLocationRptQuery);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvLoc);
                this.LoadData();
            }
        }

        private void SetEmptyLocationRptQueryEntity(EmptyLocationRptQueryEntity emptyLocationRptQuery)
        {
            base.PageQueryEntitySession = emptyLocationRptQuery;
        }

        public EmptyLocationRptQuery PreviousPage
        {
            get
            {
                return (EmptyLocationRptQuery) base.PreviousPage;
            }
        }
    }
}

